package implicitConvert

/**
  * ImplicitDemo
  *
  * @author zhangyimin
  * @date 2018-09-20 上午11:43
  * @version 1.0
  */
class Fruit(name: String) {
  def getName(): String = name
}

class Apple(name: String) {
  def getName(): String = name
}

class Banana(name: String) {
  def getName(): String = name
}

class Monkey(f:Fruit){
  def say(){println("猴子吃:"+f.getName())}
}


class ImplicitDemo {
}

object ImplicitDemo {
  def main(args: Array[String]): Unit = {

    implicit def apple2Fruit(apple: Apple): Fruit = {
      new Fruit(apple.getName())
    }

    var fruit: Fruit = new Apple("我是小苹果!")
    println(fruit.getName())
    val monkey:Monkey=new Monkey(fruit)
    println(monkey.say())
  }
}
